<template>
    <div class="f-menu" :style="{ width: userStore.asideWidth }">
        <el-menu :unique-opened="true" :collapse-transition="false" :collapse="collapse" :default-active="defaultActive"
            @select="handleSelect">
            <template v-for="(item, index) in asideMenu">
                <el-sub-menu v-if="item.child && item.child.length > 0" :index="item.name" :key="index">
                    <template #title>
                        <el-icon>
                            <component :is="item.icon"></component>
                        </el-icon>
                        <span>{{ item.name }}</span>
                    </template>
                    <el-menu-item v-for="(item2, index2) in item.child" :key="index2" :index="item2.frontpath">
                        <el-icon>
                            <component :is="item2.icon"></component>
                        </el-icon>
                        <span>{{ item2.name }}</span>
                    </el-menu-item>
                </el-sub-menu>
                <el-menu-item v-else :index="item.frontpath">
                    <el-icon>
                        <component :is="item.icon"></component>
                    </el-icon>
                    <span>{{ item.name }}</span>
                </el-menu-item>
            </template>
        </el-menu>

    </div>
</template>
<script setup>
import { computed, ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { useInfoStore } from '../../store';
const userStore = useInfoStore();
const router = useRouter();
const route = useRoute();
// 获取当前页面的路由路径
const defaultActive = ref(route.path);
const asideMenu = computed(() => {
    return userStore.menus;
})
const handleSelect = (event) => {
    defaultActive.value = event;
    router.push(event);
}
const collapse = computed(() => {
    return userStore.asideWidth !== '250px'
})



</script>
<style scoped lang='scss'>
.f-menu {
    transition: all 0.2s;
    top: 64px;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    overflow-x: hidden;
    @apply shadow-md fixed bg-light-50;
}

.f-menu::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, and Opera */
}
</style>
